package com.yufang.Day09_28;

public class D_3 {

    public static void main(String[] args) {
        int index = getAns("hello","ll");
        System.out.println(index);
    }

    private static int getAns(String haystack, String needle) {

        if(haystack.equals(needle) || needle.equals("")) return 0;
        if (haystack.equals("")) return -1;
        int left = 0;
        int right = needle.length();
        int index = -1;
        while ( (haystack.length()-left) >= right) {
            if(haystack.charAt(left) == needle.charAt(0)){
                if(haystack.substring(left,left+right).equals(needle)){
                    index = left;
                    break;
                }
            }
            left++;
        }
        return index;

//        if(haystack.indexOf(needle) == -1) return -1;
//        else return haystack.indexOf(needle);


    }

}
